package com.boxGame.android;

import net.youmi.android.AdManager;
import net.youmi.android.banner.AdSize;
import net.youmi.android.banner.AdView;
import net.youmi.android.banner.AdViewListener;
import tk.woppo.game2048.R;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	private int mScore;
	private TextView tvScore;
	
	private static MainActivity act = null;
	public static MainActivity getAct() {
		return act;
	}

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setAvd();
        act = this;
        
        tvScore = (TextView) findViewById(R.id.tv_score);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    public void clearScore() {
		mScore = 0;
		showScore();
	}
    
    public void addScore(int s) {
		mScore += s;
		showScore();
	}
    
    private void showScore() {
		tvScore.setText(mScore + "");
	}
    void setAvd(){
    	AdManager.getInstance(this).init("943da2245e7036d0",
				"2d147720c9145ed4", false);
		FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
				FrameLayout.LayoutParams.FILL_PARENT,
				FrameLayout.LayoutParams.WRAP_CONTENT);
			// 设置广告条的悬浮位置
			layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; // 这里示例为右下角
			// 实例化广告条
				AdView adView = new AdView(this,
						AdSize.FIT_SCREEN);
				// 调用Activity的addContentView函数
				this.addContentView(adView, layoutParams);

				// 监听广告条接口
				adView.setAdListener(new AdViewListener() {

					@Override
					public void onSwitchedAd(AdView arg0) {
						Log.i("YoumiAdDemo", "广告条切换");
					}

					@Override
					public void onReceivedAd(AdView arg0) {
						Log.i("YoumiAdDemo", "请求广告成功");

					}

					@Override
					public void onFailedToReceivedAd(AdView arg0) {
						Log.i("YoumiAdDemo", "请求广告失败");
					}
				});
    }
}
